//pack11jsclass

var ValuesManager=new valuesManager();

function valuesManager() {

    this.propertyToAdd=0;
    this.elementToChange=0;
    this.DefaultMaxLength=50;
    this.valueMaxLength=0;

    this.add = function(id,element,maxLength,textPopup) {
        if(maxLength) ValuesManager.valueMaxLength=maxLength;
        ValuesManager.propertyToAdd=id;
        try {
            ValuesManager.elementToChange=document.getElementById(element+"_select");
        } catch(e) {
            //alert(element+"_select");
            return false;
        }
        if(ValuesManager.elementToChange==null) {
            //alert(element+"_select");
            return false;
        }

        if(textPopup=="newtext") {
            PopupManager.open('NewTextPopup');
        } else {
            PopupManager.open('NewValuePopup');
        }
    }

    this.addHandler = function(text,xml) {
        data=text.split("::");
        if(data[0]=="error") return false;
        if(data.length<2) return false;

        var optn = document.createElement("OPTION");
        textData=data[1].split(" ");
        textValue="";
        for(nvi=0; nvi<textData.length; nvi++) {
            tempValue=textValue+" "+textData[nvi];
            if(tempValue.length>ValuesManager.valueMaxLength) {
                textValue+="...";
                break;
            } else {
                textValue=tempValue;
            }
        }
        optn.text = textValue;
        optn.value = data[0];
        //alert(ValuesManager.elementToChange);
        ValuesManager.elementToChange.options.add(optn);
        ValuesManager.elementToChange.selectedIndex=ValuesManager.elementToChange.options.length-1;
        PopupManager.close();
    }

    this.countText = function(element) {
        current=element.value.length;
        maxLength=ValuesManager.DefaultMaxLength;
        if(ValuesManager.valueMaxLength==0) {
            try {
                max=Number(document.getElementById(element.id+"_max"));
                maxLength=max.value
            } catch(e) {
                Trace(element.id+"_max not found");
            }
        } else {
            maxLength=ValuesManager.valueMaxLength;
        }

        try {
            counter=document.getElementById(element.id+"_counter");
            counter.innerHTML="&nbsp;("+(maxLength-current)+")";
            if(current>maxLength) element.value=element.value.substr(0, maxLength);
        } catch (e) {
            Trace("ValuesManager.countText => counter("+element.id+"_counter) not found");
        }
    }
	
}